package com.xxd.spring.boot.demo.hubajun.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xxd.spring.boot.demo.hubajun.Result;
import com.xxd.spring.boot.demo.hubajun.entity.StudentEntity;
import com.xxd.spring.boot.demo.hubajun.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/hubajun/student")
public class StudentController {

    @Autowired
    private StudentMapper studentMapper;

    @RequestMapping(value = "/listStudent")
    public Result student(Page page, @RequestParam Map<String, Object> paramsMap) {
        IPage resPage = studentMapper.listPage(page, paramsMap);
        return new Result().setData(resPage);
    }


    @RequestMapping(value = "/addStudent")
    public Result insertStudent(@RequestBody StudentEntity studentenity) {
        studentMapper.insertData(studentenity);
        return new Result().success();
    }

    @RequestMapping(value = "/updateStudent")
    public Result updateStudent(@RequestBody StudentEntity studentenity) {
        studentMapper.MyUpdateById(studentenity);
        return new Result().success();
    }

    @RequestMapping(value = "/delStudent/{id}")
    public Result delStudent(@PathVariable("id") Integer id) {
        studentMapper.deleteById(id);
        return new Result().success();
    }
}